package com.company;

import java.util.ArrayList;
import java.util.List;

public class Solution1 {
    public List<String> letterCombinations(String digits) {
        List<String> res = new ArrayList<>();
        if (digits.equals("")){
            return res;
        }
        else {
            String[] dicts = {"", "*", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
            res.add("");
            for (int i = 0; i < digits.length(); i++) {
                String tmp = dicts[digits.charAt(i) - '0'];
                int size = res.size();
                for (int j = 0; j < size; j++) {
                    String get = res.remove(0);
                    for (int k = 0; k < tmp.length(); k++) {
                        res.add(get + tmp.charAt(k));
                    }
                }
            }
            return res;
        }
    }

    public static void main(String[] args) {
        Solution1 solution1 = new Solution1();
        System.out.println(solution1.letterCombinations(""));
        for (String s: solution1.letterCombinations("")) {
            System.out.println(s);
        }
    }

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode res = new ListNode(Math.min(l1.val,l2.val));
        ListNode l = res;

        while (l1.next!=null&&l2.next!=null){
            if (l1.val<=l2.val){
                ListNode tmp = new ListNode(l1.val,l1.next);

                l.next = tmp;
                l1 = l1.next;
                l = tmp;
            }else {
                ListNode tmp = new ListNode(l2.val,l2.next);
                l.next = tmp;
                l2 = l2.next;
                l = tmp;
            }
        }
        if (l1.next == null){
            l.next = l2;
        }
        if (l2.next == null){
            l.next = l1;
        }
        return res;
    }
}

class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }
